# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libmaxminddb
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.2
pkgrel=1
pkgdesc="C library for reading MaxMind DB files, including the GeoIP2 databases from MaxMind (mingw-w64)"
arch=('any')
url="https://dev.maxmind.com/geoip/"
license=('Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-geoip2-database")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-libtool"
             "autoconf"
             "git"
             "patch")
options=('!emptydirs')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/maxmind/${_realname}/archive/${pkgver}.tar.gz
        "MaxMind-DB"::git+https://github.com/maxmind/MaxMind-DB.git
        libtap::git+https://github.com/zorgnax/libtap.git
        0001-libmaxminddb-1.3.2-mingw-no-undefined.patch)
sha256sums=('c0785521c7e5515f1169db90ed6e51bc2a5a000377d0fbad87e4d5a791a6e364'
            'SKIP'
            'SKIP'
            'cf09b582066d08667692e1f104f0db933a2fac19bda4df0a5182077cc015579a')

prepare() {
  cp -rf ${srcdir}/libtap ${srcdir}/${_realname}-${pkgver}/t/
  cp -rf ${srcdir}/MaxMind-DB ${srcdir}/${_realname}-${pkgver}/t/
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-libmaxminddb-1.3.2-mingw-no-undefined.patch"
  ./bootstrap
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  cp -rf ${_realname}-${pkgver} "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --disable-tests

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
